const express = require('express');
const cors = require('cors');
const Mock = require('mockjs')
const bodyParser=require('body-parser');

//const uuidv1=require('uuid/v1')
const app = express();
app.use(express.static('./public'))
app.use(bodyParser.urlencoded({extended:false}));
app.use(cors())
app.get('/pic', (req, res) => {
    res.send(
        Mock.mock({
            error: null,
            'data|10': [{
                id: '@uuid',
                'icon|+1': ['/upload/icon1.png', '/upload/icon2.png', '/upload/icon3.png', '/upload/icon4.png', '/upload/icon5.png',
                    '/upload/icon6.png', '/upload/icon7.png', '/upload/icon8.png', '/upload/icon9.png', '/upload/icon10.png'],
                'text|+1': ['超市便利', '生鲜果蔬', '烘焙蛋糕', '鲜花绿植', '医药健康', '新人专享', 'VIP会员', '领券', '邀请有赏', '签到'],
                'tip|+1': ['', '', '', '', '', '', '', '', '', '99减50']
            }]
        })

    )

});

app.get('/navs', (req, res) => {
    res.send(Mock.mock({
        error: null,
        'data|5': [{
            id: '@uuid',
            'icon|+1': ['home', 'welf', 'shopping', 'order', 'my'],
            'text|+1': ['首页', '福利', '购物车', '订单', '我的'],
            'path|+1': ['/homepage', '/welfare', '/shoppingcar', '/order', '/myself']
        }]
    }))
});
app.get('/shops', (req, res) => {
    res.send(Mock.mock({
        error: null,
        'data|7': [{
            id: '@uuid',
            'icon|+1': ['/upload/shop1.png', '/upload/shop2.png', '/upload/shop3.png', '/upload/shop4.png', '/upload/shop5.png','/upload/shop6.png','/upload/shop7.png'],
            'minicon|1': ['/upload/min-shop-icon1.png', '/upload/min-shop-icon2.png'],
            'title|+1': ['沃尔玛-新街口店', '永辉超市-茂业天地店', '家乐福-大行宫店', '华润苏果-文昌巷社区店', '南京苏果羊皮巷生活超市','萝卜青菜-后宰门精品店','水果大王-新街口店'],
            'score|3-4.1': 0,
            'mintes|5-60': 0,
            'distance|0-5.1': 0,
            'startpri|0-1': 0,
            'basepri|4-5': 0,
            'forword|1': ['达达专送', ''],
            'sale|1': ['月销售1万+', '月销售3千+', '月销售1千+', '月销售500+'],
            'tip1|1': [{
                tp: '领券',
                text: '立减8元,免5.5元运费,满49减12,满49减10,满39减8'
            },
            {
                tp: '领券',
                text: '满79减12,满69减10,满59减8'
            },
            {
                tp: '领券',
                text: '满199减20,满29减8,满29减5'
            }],
            'tip2|1':[{
                tp: '满减',
                text: '德芙士力架满69减12'
            },
            {
                tp: '满减',
                text: '联合利华洗护满88减12'
            },
            {
                tp: '满减',
                text: '统一食品饮品满20减4，满40减8，满60减12'
            },
            {
                tp: '满减',
                text: '德芙士力架满69减12'
            }]

        }]
    }))
})
app.get('/swiper1', (req, res) => {
    res.send(Mock.mock({
        error: null,
        'data|8': [{
            id: '@uuid',
            'pics|+1': ['/upload/lb1.png','/upload/lb2.png','/upload/lb3.png','/upload/lb4.png',
            '/upload/lb5.png','/upload/lb6.png','/upload/lb7.png','/upload/lb8.png',],
        }]
    }))
});
app.get('/swiper2', (req, res) => {
    res.send(Mock.mock({
        error: null,
        'data|2': [{
            id: '@uuid',
            'pics|+1': ['/upload/lb2-2.png','/upload/lb2-3.png'],
        }]
    }))
});

app.get('/swiper3',(req,res)=>{
    res.send(Mock.mock({
        id:'@uuid',
        'data|8':[{
            id:'@uuid',
            'pics|+1':['/upload/huadong1.jpg','/upload/huadong2.png','/upload/huadong3.jpg','/upload/huadong4.png','/upload/huadong5.jpg','/upload/huadong1.jpg','/upload/huadong2.png','/upload/huadong3.jpg','/upload/huadong4.png','/upload/huadong5.jpg'],
            'title|+1':['华润苏果-文昌巷社区店','华润苏果-文昌巷社区店','永辉超市-茂业天地店','南京苏果羊皮巷生活超市','永辉超市-茂业天地店','永辉超市-茂业天地店','南京苏果羊皮巷生活超市','华润苏果-文昌巷社区店','南京苏果羊皮巷生活超市','华润苏果-文昌巷社区店'],
            'price|1-100':0,
            sprice(){
                if(this.price-10<0){
                    return this.price
                }else{
                    return this.price-10
                }
            },      
        }]

    }))
})

app.get('/shopctg', (req, res) => {
    res.send(Mock.mock({
        error: null,
        'data|20': [{
            id: '@uuid',
            'text|+1': [
                        '为你优选',
                        '单品优惠',
                        '满额促销',
                        '车厘子',
                        '吃火锅',
                        '新鲜水果',
                        '时令蔬菜',
                        '肉蛋家禽',
                        '海鲜荟萃',
                        '冷藏冷冻',
                        '牛奶酸奶',
                        '为你优选',
                        '单品优惠',
                        '满额促销',
                        '车厘子',
                        '吃火锅',
                        '新鲜水果',
                        '时令蔬菜',
                        '肉蛋家禽',
                        '海鲜荟萃',
                        '冷藏冷冻',
                        '牛奶酸奶',
                        ],
            'children|0-5':[{
                id: '@uuid',
                text:'@ctitle(2,4)'

            }]
        }]
    }))
});
app.get('/sp1',(req,res)=>{
    res.send(Mock.mock({
        id:'@uuid',
        'data|10':[{
            id:'@uuid',
            'pics|+1':['/upload/sp1.jpg','/upload/sp2.jpg','/upload/sp3.jpg','/upload/sp4.jpg','/upload/sp5.jpg','/upload/sp1.jpg','/upload/sp2.jpg','/upload/sp3.jpg','/upload/sp4.jpg','/upload/sp5.jpg'],
            'title|+1':['金纺 衣物护理剂 怡神薰衣草 2.8L','伊利 安慕希希腊风味酸奶 原味 205g*12','伊利 金典纯牛奶 250ml*12 (新旧包装，随机发货）','智利进口车厘子 J级 约500g','沙糖桔 约500g','金纺 衣物护理剂 怡神薰衣草 2.8L','伊利 安慕希希腊风味酸奶 原味 205g*12','伊利 金典纯牛奶 250ml*12 (新旧包装，随机发货）','智利进口车厘子 J级 约500g','沙糖桔 约500g'],
            'text1|+1':['月售17件 好评100%','月售868件 好评97%','月售576件 好评99%','月售325件 好评71%','月售732件 好评89%','月售17件 好评100%','月售868件 好评97%','月售576件 好评99%','月售325件 好评71%','月售732件 好评89%'],
            'text2|+1':['秒杀5.31折','秒杀5.31折','秒杀7.99折','秒杀5.31折','秒杀7.52折','秒杀5.31折','秒杀7.99折','秒杀7.52折','秒杀5.31折','秒杀7.99折'],
            'price|1-100':0,
            sprice(){
                if(this.price-10<0){
                    return this.price
                }else{
                    return this.price-10
                }
            },
            'store|1-10':0
            
        }]

    }))
});
app.get('/sp2',(req,res)=>{
    res.send(Mock.mock({
        id:'@uuid',
        'data|4':[{
            id:'@uuid',
            'pics|+1':['/upload/gs21.jpg','/upload/gs22.jpg','/upload/gs23.jpg','/upload/gs24.jpg'],
            'title|+1':['康师傅 蘑菇鲜蔬面 106g','永和豆浆 甜豆浆粉速溶豆粉 720g(24包)','海欣 撒尿肉丸 320g','海欣 鱼皮豆腐 320g'],
            'text1|+1':['月售51件 好评100%','月售239件 好评100%','月售51件 好评100%','月售51件 好评100%'],
            'text2|+1':['直降8.73折','直降6.57折','直降4.95折','直降4.95折'],
            'price|1-100':0,
            sprice(){
                if(this.price-10<0){
                    return this.price
                }else{
                    return this.price-10
                }
            },
            'store|1-10':0
            
        }]

    }))
})

app.get('/gs',(req,res)=>{
    res.send(Mock.mock({
        id:'@uuid',
        'data|6':[{
            id:'@uuid',
            'pics|+1':['/upload/ggs1.jpg','/upload/ggs2.jpg','/upload/ggs3.jpg','/upload/ggs4.jpg','/upload/ggs5.jpg','/upload/ggs6.jpg'],
            
        }]

    }))
})

app.post('/dl',(req,res)=>{
    let username=req.body.username
    let psw=req.body.psw
   if(username=="17602512515"&&psw=='123456'){
       res.send({ 
           status:200,
           data:{
                username:'17602512515',
                psw:'123456'
           },
           message:'登录成功'
       })
   }else{
       res.send({
           status:400,
           data:null,
           message:'用户名或密码错误'
       })
   }
})
app.listen(3310);